<script>
	import { useConfigStore, useUserInfoStore, useIndexStore } from '@/store/index';
	import { getUserInfo } from '@/common/api/user';
	import { newMsgAPI } from '@/common/api';
	export default {
		onLaunch: async function(options) {
			const configState = useConfigStore();
			const userInfoState = useUserInfoStore();
			const indexState = useIndexStore();

			configState.setScene(options.scene);
            //#ifdef MP-WEIXIN
            const appInfo = uni.getAppBaseInfo();
            configState.setWXSDKVersion(appInfo.hostSDKVersion);


            //朋友圈进入小程序快照场景
			if(options.scene == 1154) return;
            //#endif

            //用户信息是否有id属性
            // if(!userInfoState.userInfo.id) {
            //     try {
            //         let userInfoRes = await getUserInfo();
            //         if(userInfoRes.status === 0) {
			// 			userInfoState.setUserInfo(userInfoRes.detail);
            //             console.log('app');
            //             console.log(userInfoState.userInfo);
            //             uni.setStorage({
            //                 key: 'userInfo',
            //                 data: userInfoRes.detail
            //             })
            //         }
            //     }catch(err) {}
            // }

            //未读消息通知
            // try {
            //     let unreadMessage = await newMsgAPI();
            //     if(unreadMessage.status === 0 && unreadMessage.detail !== 0){
			// 		indexState.setBadgeByType({index: 4, value: unreadMessage.detail>99?99:unreadMessage.detail})
			// 		indexState.setNewMessage(true)
            //     }
            // } catch (error) {}

            //版本更新
            const updateManager = uni.getUpdateManager();
            updateManager.onCheckForUpdate();

            updateManager.onUpdateReady(function (res) {
              uni.showModal({
                title: '更新提示',
                content: '新版本已下载完成，是否重启小程序？',
                showCancel: false,
                success(res) {
                  if (res.confirm) {
                    // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
                    updateManager.applyUpdate();
                  }
                }
              });
            });

            updateManager.onUpdateFailed();
		},
		onShow: function(options) {
			//获取更多转发到群的信息
			//#ifdef MP-WEIXIN
			if(!options) return
			wx.getShareInfo({
				shareTicket: options.shareTicket,
				success: res => {}
			})
			//#endif
		},
		onHide: function() {
		}
	}
</script>

<style lang="scss">
	@import "@/uni_modules/uview-plus/index.scss";
	@import './common/uni.scss';
    @import './common/css/color.scss';
    @import './common/css/margin.scss';
    @import './common/css/text-style.scss';
    @import './common/css/animation.scss';
    @import "./common/css/ipang.css";
	page {
        font-size: 28rpx;
		color: #3E3A3A;
        background-color: #F4F5F6;
    }
</style>
